package com.itbuka.search.listener;

import com.itbuka.search.config.RabbitConfig;
import com.itbuka.search.service.ESManagerService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SearchListener {

    @Autowired
    private ESManagerService esManagerService;

    @RabbitListener(queues = {RabbitConfig.GOODS_QUEUE})
    public void goods(String id) {
        //创建索引库结构
        esManagerService.createMappingAndIndex();
        //导入数据到ES索引库
        esManagerService.importById(id);
    }


    @RabbitListener(queues = RabbitConfig.GOODS_DOWN_QUEUE)
    public void goodsDownListener(String id) {
        //删除索引库
        esManagerService.deleteById(id);
    }
}